package de.bensoft.jrail.client.ui.controls;

import javafx.beans.binding.Bindings;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.scene.control.TextField;
import javafx.util.converter.NumberStringConverter;

public class NumberField extends TextField {

	private LongProperty lp;
	
	public LongProperty longProperty() { return lp; }
	
	public NumberField() {
		lp = new SimpleLongProperty();
		
		Bindings.bindBidirectional(textProperty(), lp, new NumberStringConverter());
	}
	
	
	@Override 
	public void replaceText(int start, int end, String text) {
		if (text.matches("[0-9]*")) {
			super.replaceText(start, end, text);
		}
	}

	@Override 
	public void replaceSelection(String text) {
		if (text.matches("[0-9]*")) {
			super.replaceSelection(text);
		}
	}
}
